<template>
  <transition name="slide">
  <music-list :s-name="sname" :s-avatar="savatar" :s-song="songs"> </music-list>
  </transition>
</template>

<script type="text/ecmascript-6">
  import MusicList from 'components/music-list/music-list'
  import {getSingerDetail} from 'api/singer'
  import {mapGetters} from 'vuex'
  import {ERR_OK} from 'api/config'
  import {createSong} from 'common/js/song'
  export default {
    data(){
      return{
        songs:[]
      }
    },
    computed:{
      sname(){
        return this.singer.name
      },
      savatar(){
        return this.singer.avatar
      },
      ...mapGetters([
        'singer'
      ])
    },
    created(){
      this._getDetail()
    },
    updated(){
      console.log('vuex getters',this.singer.name)
    },
    methods:{
      _getDetail(){
        if (!this.singer.id){
          this.$router.push('/singer')
          return
        }
        getSingerDetail(this.singer.mid).then((res)=>{
          if(res.code===ERR_OK){
            console.log("-**-singer detail-res.data.list",res.data.list.lengt)
            this.songs=this._normalizeSongs(res.data.list)
          }

        })
      },
      _normalizeSongs(list){
        //格式化歌曲
        let ret =[]
        list.forEach((item)=>{
          let {musicData}=item
          //songid/albumid是必须选项
          if(musicData.songid && musicData.albumid){
            ret.push(createSong(musicData))
          }
        })
        return ret
      }
    },
    components:{
      MusicList
    }
  }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  .singer-detail
    position: fixed;
    width: 100%;
    height: 100%;
    left:0;
    top :0;
    overflow: hidden;
    background: #222;
    z-index:100;

  .slide-enter-active, .slide-leave-active
    transition: all 0.3s

  .slide-enter, .slide-leave-to
    transform: translate3d(100%, 0, 0)
</style>
